//操作人姓名
var operateUserName = JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name;

//
var channelImportantSkuId = sessionStorage.getItem("channelImportantSkuId");
var customerId = sessionStorage.getItem("customerId");


$(function () {
    console.log("321");
    getChannelImportantSkuDetail();
})

//渠道重点商品明细-查询数据接口
function getChannelImportantSkuDetail () {
    var param = {
        channelImportantSkuId: channelImportantSkuId,
        customerId: customerId,
        operator: operateUserName
    };
    $.ajax({
        url: root.dockingplatform.getChannelImportantSkuDetail,
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify(param),
        success: function (result) {
            if (result.errorCode == 0) {
                $("#skuCode").html(result.data.skuCode);
                $("#channelSkuCode").html(result.data.channelSkuCode);
                $("#channelSkuName").html(result.data.channelSkuName);
                $("#channelSkuName").attr("title", result.data.channelSkuName);
                $("#channelBrand").html(result.data.channelBrand);
                $("#channelUnit").html(result.data.channelUnit)
                var channelState = result.data.channelState;
                if (channelState == 1) {
                    $("#channelState").html("上架");
                } else if (channelState == 0) {
                    $("#channelState").html("下架");
                }
                var channelInBoundStatus = result.data.channelInBoundStatus;
                if (channelInBoundStatus == 0) {
                    $("#channelInBoundStatus").html("");
                } else if (channelInBoundStatus == 1) {
                    $("#channelInBoundStatus").html("已入库");
                } else if (channelInBoundStatus == 2) {
                    $("#channelInBoundStatus").html("入库失败");
                    $("#channelFailReason").html(result.data.channelFailReason);
                }
                $("#specifications").html(result.data.specifications);
                $("#channelIntroduction").html(result.data.channelIntroduction);
                $("#channelPrice").html(result.data.channelPrice);

                $.ajax({
                    url: root.dockingplatform.findCategoryById,
                    cache: false,  //禁用缓存
                    type: "POST",
                    dataType: 'json',
                    contentType: "application/json",
                    data: JSON.stringify({ categoryId: result.data.categoryId }),
                    success: function (data) {
                        if (data.data != null) {
                            $("#categoryId").html(data.data.categoryName);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest);
                    }
                });
                var channelParam = JSON.parse(result.data.channelParam);
                /* for (var i = 0; i < channelParam.length; i++) {
                    for (var v in rchannelParamsult[i]) {
                        console.log(v + ':' + result[i][v]);
                    }
                } */
                var html_Content = "";
                for (var i = 0; i < channelParam.length; i++) {
                    if (i % 2 == 0) {
                        html_Content += "<div class=\"pro-row\">";
                    }

                    html_Content += "<div class=\"pro-col\"><lable class=\"form-label\">" + channelParam[i].paramname + "：</lable><span>" + channelParam[i].paramvalue + "</span></div>";

                    if (i % 2 != 0) {
                        html_Content += "</div>";
                    }
                }
                $("#pro-param-info").html(html_Content);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}